package dkbta.ontology.loading;

import static dkbta.ontology.loading.OntologyParser.parseScaledValues;

import org.w3c.dom.Element;

import dkbta.ontology.Ontology;
import dkbta.ontology.elements.ElementType;
import dkbta.ontology.elements.primitive.PrimitiveDef;
import dkbta.ontology.loading.OntologyParser.ElementParser;
import dkbta.ontology.values.ScaledValues;

final class PrimitiveParser implements ElementParser{
	private final Ontology _ontology;

	public PrimitiveParser(Ontology ontology){
		_ontology = ontology;
	}

	@Override
	public ElementType getElementType(){
		return ElementType.PRIMITIVE;
	}

	public void parseElement(Element primitive, String name, String componentType)
			throws OntologyException{
		ScaledValues sv = parseScaledValues(primitive);
		if (sv == null){
			throw new OntologyException("The primitive " + name + " has no values");
		}
		PrimitiveDef pd = new PrimitiveDef(name, componentType, sv);
		_ontology.addPrimitive(pd);

	}
}